package com.nf.action;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class TestAction {
    public static void main(String[] args) {
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        ComboPooledDataSource comb = (ComboPooledDataSource) ac.getBean("dataSource");
        try{
            Connection connection = comb.getConnection();
            PreparedStatement preparedStatement = connection.prepareStatement("select * from student");
            ResultSet rs = preparedStatement.executeQuery();
            while(rs.next()){
                Integer id = rs.getInt("id") ;
                System.out.println(id);
                String  name= rs.getString("name");
                System.out.println(name);
            }
            rs.close();
            preparedStatement.close();
            System.out.println(connection);
            connection.close();
        } catch (Exception e) {
        }

    }
}
